<template>
  <div>
    <van-nav-bar :title="$route.meta.title" left-text="返回" left-arrow :fixed="true" :placeholder="true" @click-left="$router.go(-1)" :right-text="auditBtn" @click-right="editApply()" />
    <div>
      <div class="headerbox">
        <div class="header_top" :style="{ width: columns.length * 3 + 'rem' }">
          <div class="header_item" v-for="(item, index) in columns" :key="index" @click="handleClick(index)" :class="tabIndex == index ? 'active' : ''">
            <div class="txt">{{ item.number }}</div>
            <div class="txt1">{{ item.bizDate }}</div>
          </div>
        </div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">收款信息</div>
        <div class="carInfo_item">收款单号：{{ dataSource.billNumber }}</div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">收款日期：{{ dataSource.realPayDate }}</div>
          <div class="carInfo_item_price">单据状态：{{ dataSource.billStatus }}</div>
        </div>

        <div class="carInfo_item flex">
          <div class="carInfo_item_price">品牌：{{ dataSource.brand }}</div>
          <div class="carInfo_item_price">展厅：{{ dataSource.showOrgName }}</div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">合同收款金额：{{ dataSource.totalAmount }}</div>
          <div class="carInfo_item_price">贴息费用：{{ dataSource.InterestAmount }}</div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">银行收款金额：{{ dataSource.BankRecAmount }}</div>
          <div class="carInfo_item_price">是否使用预收款：{{ dataSource.isAdvancePay ? '是' : '否' }}</div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">款项性质：{{ dataSource.receiveType }}</div>
          <div class="carInfo_item_price">收款方式：{{ dataSource.settleType }}</div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">收款公司：{{ dataSource.signCompany }}</div>
          <div class="carInfo_item_price">分期金融机构：{{ dataSource.installBank }}</div>
        </div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">付款人：{{ dataSource.payerName }}</div>
          <div class="carInfo_item_price">客户银行卡号：{{ dataSource.custCardNO }}</div>
        </div>
        <div class="carInfo_item">备注：{{ dataSource.note }}</div>
      </div>

      <div class="carInfo">
        <div class="carInfo_title">销售信息</div>
        <div class="carInfo_item">销售合同单号：{{ dataSource.saleContractNumber }}</div>
        <div class="carInfo_item">销售车辆：{{ dataSource.carModel }}</div>
        <div class="carInfo_item">合同金额：{{ dataSource.amount }}</div>
        <div class="carInfo_item">合同累计收款金额：{{ dataSource.totalReceAmount }}</div>
      </div>

      <div class="carInfo" v-if="dataSource.refundType">
        <div class="carInfo_title">退款信息</div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">退款类型：{{ dataSource.refundType }}</div>
          <div class="carInfo_item_price">退款方式：{{ dataSource.refundWay }}</div>
        </div>
        <div class="carInfo_item">退款日期：{{ dataSource.refundDate }}</div>
        <div class="carInfo_item">付款公司：{{ dataSource.paymentCompany }}</div>
        <div class="carInfo_item">付款账号：{{ dataSource.paymentBankNo }}</div>
        <div class="carInfo_item">开户行：{{ dataSource.openBank }}</div>
        <div class="carInfo_item flex">
          <div class="carInfo_item_price">退款账号：{{ dataSource.refundNo }}</div>
          <div class="carInfo_item_price">退款户名：{{ dataSource.reFundCustomer }}</div>
        </div>
        <div class="carInfo_item">退款原因：{{ dataSource.remark }}</div>
        <div class="carInfo_item">付款人：{{ dataSource.payerName }}</div>
      </div>

      <div class="goBack" @click="goBack">返回</div>
      <!-- 审核情况 -->
      <AuditRecord :visible="auditVisible" :billId="dataSource.billId ? dataSource.billId : detailId" @close="auditVisible = false"></AuditRecord>
    </div>
  </div>
</template>

<script>
import sellManageApi from "@/api/sellManageApi";
import AuditRecord from "@/components/AuditRecord";
export default {
  components: {
    AuditRecord
  },
  data() {
    return {
      active: "",
      detailId: "", // 当前单据ID
      orderId: "", // 当前合同订单ID
      desBosType: "", // 单据类型 desBosType
      columns: [],
      tabIndex: 0,
      dataSource: {
        billId: "", //单据Id
        billNumber: "", //出库单编号
        realPayDate: "", //收款日期
        billStatus: "", //收款状态
        brand: "", //所属品牌
        showOrgName: "", //所属展厅
        signCompany: "", //收款公司
        signCompanyId: "", //收款公司
        totalAmount: "", //合同收款金额
        isAdvancePay: "", //是否使用预收款
        receiveType: "", //款项性质
        settleType: "", //收款方式
        installBank: "", //分期金融机构
        payerName: "", //付款人
        custCardNo: "", //客户银行卡号
        note: "", //备注
        saleContractNumber: "", //合同编号
        carModel: "", //二手车型
        amount: "", //合同总价
        totalReceAmount: "", //累计收款金额
        InterestAmount: "", //贴息费用
        BankRecAmount: "", //银行收款金额
        refundType: "", //退款类型
        refundWay: "", //退款方式
        refundDate: "", //退款日期
        paymentCompany: "", //付款公司
        paymentBankNo: "", //付款账号
        openBank: "", //开户行
        refundNo: "", //退款账号
        reFundCustomer: "", //退款户名
        remark: "" //退款原因
      },
      auditBtn: "",
      auditVisible: false
    };
  },
  mounted() {
    if (this.$route.query) {
      this.detailId = this.$route.query.billId;
      this.orderId = this.$route.query.orderId;
      this.desBosType = this.$route.query.desBosType;
      console.log(this.detailId);
      console.log(this.orderId);
      console.log(this.desBosType);
      this.getList(this.orderId);
    }
  },
  methods: {
    getDetail() {
      sellManageApi
        .secondHandCarFacade({
          method: "getSaleReceiveDataById", //固定值
          billId: this.columns[this.tabIndex].billId //单据Id，必填，String
        })
        .then(res => {
          if (res.code == 1) {
            this.dataSource = res.data;
            if (this.dataSource.billStatus != "保存") {
              this.auditBtn = "审批情况";
            }
          }
        });
    },
    getList() {
      // 根据类型ID获取单据列表
      sellManageApi
        .secondHandCarFacade({
          method: "getDestInfoBySourceIdAndDestBosType", //固定值
          userId: "", //用户ID，必填，String
          orgId: "", //登录组织Id，必填，String
          billId: this.orderId, //单据Id，必填，String
          desBosType: this.desBosType
        })
        .then(res => {
          if (res.code == 1) {
            if (res.data.length >= 1) {
              this.columns = res.data;

              this.getDetail();
            } else {
              this.$toast.fail("暂无该单据");
            }
          } else {
            this.$toast.fail("暂无该单据");
          }
        });
    },

    handleClick(index) {
      this.tabIndex = index;
      this.getDetail();
    },
    goBack() {
      this.$router.go(-1);
    },
    editApply() {
      this.auditVisible = true;
    }
  }
};
</script>
<style lang="less" scoped>
.headerbox {
  width: 100%;
  overflow-x: auto;
  &::-webkit-scrollbar {
    display: none;
  }
}
.header_top {
  display: flex;
  align-self: center;
  padding: 10px;
  overflow-x: auto;
  // width: 12rem;
  .header_item {
    width: 3rem;
    background: #fff;
    padding: 10px 15px;
    font-size: 14px;
    border-radius: 5px;
    margin-right: 10px;
    .txt {
      margin-bottom: 5px;
    }
    &.active {
      border: 1px solid #ccc;
      box-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
    }
  }
}
.carInfo {
  padding: 10px;
  background: #fff;
  margin-bottom: 10px;
  .source {
    padding-left: 0 !important;
    margin-bottom: 10px;
    justify-content: space-between;

    .source_txt {
      font-size: 16px;
    }
  }

  .carInfo_No {
    margin-bottom: 15px;
    .carInfo_No_item {
      border-right: 1px solid #ccc;
      padding-right: 5px;
      margin-right: 5px;
      font-size: 16px;
      color: #333;
      &:last-child {
        border: none;
      }
    }
  }
  .carInfo_item {
    font-size: 16px;
    margin-bottom: 5px;
    color: #333;
    .carInfo_item_price {
      width: 50%;
    }
  }
  .carInfo_title {
    font-size: 16px;
    color: #333;
    margin-bottom: 10px;
    font-weight: bold;
  }
}
.goBack {
  width: 80%;
  background: #2381e6;
  color: #fff;
  font-size: 16px;
  margin: auto;
  border-radius: 5px;
  padding: 10px;
  text-align: center;
  margin-bottom: 25px;
}
</style>
